﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace BHair
{
    public partial class frmhf : Form
    {
        public frmhf()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            this.txtlj.Text = openFileDialog1.FileName.ToString();
            /*string lj=this.txtlj.Text;
            string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
            SqlConnection conn1 = new SqlConnection();
            string sql1 = string.Format("use master;restore database BHairDB from disk='{0}'",lj);
            try 
            {
                conn1.Open();
                SqlCommand comm1 = new SqlCommand(sql1,conn1);
                comm1.ExecuteNonQuery();
                MessageBox.Show("数据库恢复成功");
                conn1.Close();
            }
            catch(Exception ex)
            {
                conn1.Close();
                MessageBox.Show("数据库恢复失败，原因为："+"\t"+ex.Message);
            }
             * */
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.txtlj.Text = openFileDialog1.FileName.ToString();
            string lj = this.txtlj.Text;
            string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
            SqlConnection conn1 = new SqlConnection(constr);
            string sql1 = string.Format("use master;restore database BHairDB from disk='{0}' with replace", lj);
            try
            {
                conn1.Open();
                SqlCommand comm1 = new SqlCommand(sql1, conn1);
                comm1.ExecuteNonQuery();
                MessageBox.Show("数据库恢复成功");
                conn1.Close();
            }
            catch (Exception ex)
            {
                conn1.Close();
                MessageBox.Show("数据库恢复失败，原因为：" + "\t" + ex.Message);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            frmbak ba = new frmbak();
            ba.ShowDialog();
        }
    }
}
